home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MyGrowZones.p < prev    next >
Encoding:
Text File  |  1995-10-23  |  1.9 KB  |  105 lines  |  [TEXT/CWIE]

  1. unit MyGrowZones;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.  
  8.     procedure StartupGrowZones;
  9.     procedure ConfigureGrowZones(size: longint; alertid: integer);
  10.     function MemoryCritical: boolean;
  11.     function EnoughSpace (total, contig: longint): boolean;
  12.  
  13. implementation
  14.  
  15. {$IFC undefined GrowZoneAlerts}
  16. {$SETC GrowZoneAlerts := 1}
  17. {$ENDC}
  18.  
  19.     uses
  20.         Memory, OSUtils, 
  21. {$IFC GrowZoneAlerts}
  22.         MyCleverAlerts, 
  23. {$ENDC}
  24.         PreserveA5, MyCallProc, MyStartup;
  25.  
  26.     var
  27.         gzh: handle;
  28.         gz_size: longINt;
  29.         lastgzh: handle;
  30.         id: integer;
  31.  
  32.     function MyGrowZone (size: longint): longint;
  33.         var
  34.             saved_A5:Ptr;
  35.     begin
  36.         size:=size; { UNUSED! }
  37.         saved_A5 := SetPreservedA5;
  38.         if gzh <> nil then begin
  39.             MyGrowZone := GetHandleSize(gzh);
  40.             DisposeHandle(gzh);
  41.             gzh := nil;
  42.         end
  43.         else begin
  44.             MyGrowZone := 0;
  45.         end;
  46.         RestoreA5(saved_A5);
  47.     end;
  48.  
  49.     function MemoryCritical: boolean;
  50.     begin
  51.         MemoryCritical := gzh = nil;
  52.     end;
  53.  
  54.     function EnoughSpace (total, contig: longint): boolean;
  55.         var
  56.             t, c: longint;
  57.     begin
  58.         PurgeSpace(t, c);
  59.         EnoughSpace := not MemoryCritical & (t >= total) & (c >= contig);
  60.     end;
  61.  
  62.     procedure IdleGrowZone;
  63.     begin
  64.         if gzh = nil then begin
  65.             gzh := NewHandle(gz_size);
  66. {$IFC GrowZoneAlerts}
  67.             if (gzh = nil) and (lastgzh <> nil) and (id > 0) then begin
  68.                 CleverNotifyAlert(id);
  69.             end;
  70. {$ENDC}
  71.             lastgzh := gzh;
  72.         end;
  73.     end;
  74.  
  75.     procedure ConfigureGrowZones(size: longint; alertid: integer);
  76.     begin
  77.         gz_size := size;
  78.         id := alertid;
  79.     end;
  80.     
  81.     function InitGrowZone(var msg: integer): OSStatus;
  82.     begin
  83.         msg := msg; { Unused }
  84.         SetGrowZone(NewProc(@MyGrowZone,uppPascal44ProcInfo));
  85.         gzh := nil;
  86.         lastgzh := nil;
  87.         IdleGrowZone;
  88.         InitGrowZone := noErr;
  89.     end;
  90.  
  91.     procedure FinishGrowZone;
  92.     begin
  93.         if gzh <> nil then begin
  94.             DisposeHandle(gzh);
  95.             gzh := nil;
  96.         end;
  97.     end;
  98.  
  99.     procedure StartupGrowZones;
  100.     begin
  101.         StartupPreserveA5;
  102.         SetStartup(InitGrowZone, IdleGrowZone, 30, FinishGrowZone);
  103.     end;
  104.     
  105. end.